package com.jspgou.cms.dao.impl;

import org.hibernate.Criteria;
import org.springframework.stereotype.Repository;

import com.jspgou.common.hibernate3.Finder;
import com.jspgou.common.hibernate3.HibernateBaseDao;
import com.jspgou.common.page.Pagination;
import com.jspgou.cms.dao.ReportDao;
import com.jspgou.cms.entity.Report;

@Repository
public class ReportDaoImpl extends HibernateBaseDao<Report, Long> implements ReportDao {
	public Pagination getPage(int pageNo, int pageSize) {
		Criteria crit = createCriteria();
		Pagination page = findByCriteria(crit, pageNo, pageSize);
		return page;
	}
	
	
	
	
	public Pagination getPage(Long memberId,Long storeId,int pageNo, int pageSize) {
		Finder f=Finder.create("from Report bean where 1=1");
		if(memberId!=null){
			f.append(" and bean.member.id=:memberId");
			f.setParam("memberId", memberId);
		}
		if(storeId!=null){
			f.append(" and bean.store.id=:storeId");
			f.setParam("storeId",storeId);
		}
		return find(f,pageNo,pageSize);
	}

	public Report findById(Long id) {
		Report entity = get(id);
		return entity;
	}

	public Report save(Report bean) {
		getSession().save(bean);
		return bean;
	}

	public Report deleteById(Long id) {
		Report entity = super.get(id);
		if (entity != null) {
			getSession().delete(entity);
		}
		return entity;
	}
	
	@Override
	protected Class<Report> getEntityClass() {
		return Report.class;
	}
}